import time

import pyautogui
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys


def login(driver):
    driver.implicitly_wait(5)
    driver.get("http://172.17.66.19:8080/#/login?redirect=%2Fproduct-list")
    driver.maximize_window()
    driver.find_element(By.NAME, "username").send_keys("lvdelin111")
    driver.find_element(By.NAME, "password").send_keys("123456")
    driver.find_element(By.CSS_SELECTOR, ".el-form > .el-button").click()


def enter_record(driver):
    driver.find_element(By.CSS_SELECTOR, "ul[role='menubar'] > div:nth-child(2) > a").click()


class TestUntitled:
    driver = webdriver.Chrome()


    # def setup_method(self):
    # self.driver = webdriver.Chrome()
    # self.vars = {}
    #
    # def teardown_method(self):
    # self.driver.quit()

    def scale(self):
        login(self.driver)
        time.sleep(3)
        enter_record(self.driver)
        time.sleep(3)
        # self.driver.execute_script("document.body.style.transform='scale(0.5)'")
        pyautogui.keyDown("ctrl")
        pyautogui.press('-', presses=4)
        pyautogui.keyUp("ctrl")
        time.sleep(3)

    def test(self):
        login(self.driver)
        getted = False
        a = ""
        while not getted:
            try:
                a += self.driver.find_element(By.CSS_SELECTOR, ".el-message--error > p").text
            except Exception:
                getted = False
                print(False)
                continue
            getted = True
        print(a)


with TestUntitled() as a:
    a.test()
